﻿Imports WPFGlue.Framework

Namespace Commanding
    Public Class CommandReference
        Inherits CommandBase

        Public Shared ReadOnly CommandProperty As DependencyProperty = DependencyProperty.Register("Command", GetType(CommandBase), GetType(CommandReference))
        Public Property Command As CommandBase
            Get
                Return GetValue(CommandProperty)
            End Get
            Set(ByVal value As CommandBase)
                SetValue(CommandProperty, value)
            End Set
        End Property

        Protected Overrides Sub Attach(ByVal base As Object)
            If Command IsNot Nothing Then
                Dim icommand As IStickyComponent = Command
                icommand.OnAttach(base, EventArgs.Empty)
            End If
        End Sub

        Protected Overrides Function CreateInstanceCore() As System.Windows.Freezable
            Return New CommandReference
        End Function

        Protected Overrides Sub Detach(ByVal base As Object)
            If Command IsNot Nothing Then
                Dim icommand As IStickyComponent = Command
                icommand.OnDetach(base, EventArgs.Empty)
            End If
        End Sub

        Public Overrides Function FindName(name As String) As CommandBase
            Dim result As CommandBase = Nothing
            If Command IsNot Nothing Then
                result = Command.FindName(name)
            End If
            Return result
        End Function
    End Class
End Namespace
